Ext.Loader.setConfig({enabled: true});
//Ext.Loader.setPath({'Ext.ux' : 'extjs4/ux','Ext.ux.exporter':'extjs4/ux/exporter'});
Ext.Loader.setPath({'Ext.ux' : 'extjs4/ux'});
Ext.require([
             'Ext.grid.*',
             'Ext.data.*',
             'Ext.ux.grid.FiltersFeature',
             'Ext.toolbar.Paging',
             'Ext.ux.ajax.JsonSimlet',
             'Ext.ux.ajax.SimManager',
             'Ext.ux.grid.Printer'          
]);
Ext.define('TS.view.rp.RpAPayBillList',{
	extend: 'Ext.panel.Panel',
	border: false,
	bodyPadding:0,
	layout: 'border',
	alias: 'widget.rpapaybilllist',
	title: '应付单列表',
	initComponent:function() {		
		this.items = [
		 {
		 	xtype: 'panel',
		 	title: '检索',
		 	region: 'north',
		 	height: 100,
		 	collapsible: true,
		 	border: false,
		 	buttonAlign: 'left',
		 	header: {iconCls: 'bill-search-button'},
		 	layout: 'hbox',
		 	items: [
		 	    {xtype: 'hiddenfield',name:'custId'},
		 	    {xtype: 'datefield',name:'begDate',fieldLabel: '开始日期:',format:'Y-m-d',value:new Date(),margin:'10,10,10,10'},
		 	    {xtype: 'datefield',name:'endDate',fieldLabel: '截止日期:',format:'Y-m-d',value:new Date(),margin:'10,10,10,10'},
		 	    {
		 	    	xtype: 'triggerfield',name:'customer',fieldLabel:'客户:',width:400,margin:'10,10,10,10',
		 	    	emptyText:'请输入客户编码或名称',trigger1Cls:Ext.baseCSSPrefix + 'form-search-trigger',
		 	    	onTriggerClick:function(e){e.keyCode=e.ENTER;this.fireEvent('specialkey',this,e);}
		 	    },		    	    
		 	    {xtype: 'button',text:'查询',margin:'10,10,10,10',action:'search',iconCls:'bill-find-button'},
		 	    {xtype: 'button',text:'高级检索',margin:'10,10,10,10',action:'advsearch',iconCls:'bill-search-button'}
		 	]
		 },
			{
				xtype:'gridpanel',
				title:'查询结果',
				header:false,
				border:false,
				region:'center',
				store:'TS.store.rp.APayBillStore',
				selType:'checkboxmodel',//设定选择模式
				multiSelect:true,//运行多选
			    features: [{
			        ftype: 'summary'
			    },{
			        ftype: 'filters',
			        // encode and local configuration options defined previously for easier reuse
			        encode: false, // json encode the filter query
			        local: true,   // defaults to false (remote filtering)
		
			        // Filters are most naturally placed in the column definition, but can also be
			        // added here.
			        filters: [{
			            type: 'string',
			            dataIndex: 'arpBillCode'
			        },{
			        	type:'date',
			        	dataIndex:'billDate'
			        },{
			        	type:'list',
			        	options:['应付单','其他应付单'],
			        	dataIndex:'arpBillName'
			        },{
			        	type:'date',
			        	dataIndex:'arpData'
			        },{
			        	type:'string',
			        	dataIndex:'customer.customerCode'
			        },{
			        	type:'numeric',
			        	dataIndex:'amount'
			        },{
			        	type:'numeric',
			        	dataIndex:'checkAmount'
			        },{
			        	type:'boolean',
			        	dataIndex:'checkStatus'
			        },{
			        	type:'boolean',
			        	dataIndex:'archived'
			        },{
			        	type:'numeric',
			        	dataIndex:'fyear'
			        },{
			        	type:'numeric',
			        	dataIndex:'period'
			        },{
			        	type:'string',
			        	dataIndex:'remark'
			        }]			    	
			    }],					    
				columns:[
						   {header:'年份',dataIndex:'fyear',width:50,align:'right'},
						   {header:'期间',dataIndex:'period',width:50,align:'right'},
				       {
				    	   header:'单据编号',dataIndex:'arpBillCode',width:100,
				    	   summaryType:'count',summaryRenderer: function(value, summaryData, dataIndex) {return '<b>' + Ext.String.format('合计[{0}]:', value) + '</b>'; }
				       },
					   {header:'单据类型',dataIndex:'arpBillName',width:80},
					   {header:'日期',dataIndex:'billDate',width:80,renderer : Ext.util.Format.dateRenderer('Y-m-d')},
					   {header:'应付日期',dataIndex:'arpDate',width:80,renderer : Ext.util.Format.dateRenderer('Y-m-d')},
					   {header:'客户编码',filterable:true,width:80,renderer:function(value,metaData,record){return record.getcustomer().get('customerCode');}},
					   {header:'客户名称',width:250,renderer:function(value,metaData,record){return record.getcustomer().get('customerName');}},
					   {header:'应付金额',dataIndex:'amount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
					   {header:'核销金额',dataIndex:'checkAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
					   {header:'核销状态',dataIndex:'checkStatus',width:80,renderer:function(value){if(value==0) return '未核销'; else return '已核销';}},
					   {header:'归档状态',dataIndex:'archived',width:60,renderer:function(value){if(value) return '是'; else return '否';}},
					   {header:'部门',width:65,renderer:function(value,metaData,record){return record.getdept().get('deptName');}},
					   {header:'业务员',width:65,renderer:function(value,metaData,record){return record.getemp().get('empName');}},
					   {header:'制单人',width:65,renderer:function(value,metaData,record){return record.getmaker().get('empName');}},
					   {header:'备注',dataIndex:'remark',width:200}
				],
				dockedItems:[{
					xtype:'pagingtoolbar',
					store:'TS.store.rp.APayBillStore',
					dock:'bottom',
					displayInfo:true,
					items:[{
						text:'清除过滤条件',
						iconCls:'button-clear-filter',
						handler:function(){
							var grid = this.up().up('gridpanel');
							grid.filters.clearFilters();
						}
					},{
						xtype:'exporterbutton',
						component:this.up('gridpanel'),
						text:'导出 Excel',
						iconCls:'bill-export-button'
					}]
				}],
				tbar:[
						{xtype:'button',text:'新增',action:'createBill',iconCls:'bill-add-button'},
						{xtype:'button',text:'编辑',action:'editBill',iconCls:'bill-edit-button'},
						{xtype:'button',text:'删除',action:'deleteBill',iconCls:'bill-delete-button'},
						{xtype:'button',text:'归档',action:'archiveBill',iconCls:'bill-archive-button'},
						{xtype:'button',text:'反归档',action:'unArchiveBill',iconCls:'bill-unarchive-button'},
						{xtype:'button',text:'打印',action:'printBill',iconCls:'bill-printer-button'},
						{xtype:'button',text:'导出',action:'exportBill',iconCls:'bill-export-button'}				
				]
			}	              
		];
		this.callParent(arguments);
	}
});